﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brain;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Demos
{
    public class Camera2DSample : DemoScreen
    {
        public Camera2D Camera;

        public Camera2DSample()
        {
            Camera = new Camera2D(this);
            Engine.Instance.CameraManager.Camera2D = Camera;
            Camera.Draw();

            ProceduralChecker Checker = new ProceduralChecker(1024, 12,Color.Black, Color.White);
            Sprite s = new Sprite();
            s.Texture = Checker;
            s.Rendering = SpriteRendering.Rendered;

            Vector2[] vec = ArrayUtil.MakeArray(new Vector2(-1000, -1000), 10, new Vector2(400, 0), 10, new Vector2(0, 400));
            for (int i = 0; i < vec.Length; i++)
            {
                Vector2 vector = vec[i];
                Sprite sprite = new Sprite();
                sprite.BoundsRectangleColor = Color.White;
                sprite.BoundsRectangle = new Rectangle((int)vector.X, (int)vector.Y, 100, 100);
                sprite.Rendering = SpriteRendering.Rendered;
                sprite.Shadow = 2;
            }
        }

        public override void Update()
        {
            base.Update();

            float Speed = 5;
            if (Engine.Instance.InputManager.IsKeyDown(Keys.W) ||
                Engine.Instance.InputManager.IsAnyPlayerButtonDown(Buttons.LeftThumbstickUp))
            {
                Camera.Position += new Vector2(0, Speed);
            }
            if (Engine.Instance.InputManager.IsKeyDown(Keys.S) ||
                Engine.Instance.InputManager.IsAnyPlayerButtonDown(Buttons.LeftThumbstickDown))
            {
                Camera.Position -= new Vector2(0, Speed);
            }
            if (Engine.Instance.InputManager.IsKeyDown(Keys.A) ||
                Engine.Instance.InputManager.IsAnyPlayerButtonDown(Buttons.LeftThumbstickLeft))
            {
                Camera.Position += new Vector2(Speed, 0);
            }
            if (Engine.Instance.InputManager.IsKeyDown(Keys.D) ||
                Engine.Instance.InputManager.IsAnyPlayerButtonDown(Buttons.LeftThumbstickRight))
            {
                Camera.Position -= new Vector2(Speed, 0);
            }

            float mouse = Engine.Instance.InputManager.GetMouseWheelDifference();
            if (mouse > 0)
            {
                mouse = 1;
            }
            if (mouse < 0)
            {
                mouse = -1;
            }
            Camera.Zoom += mouse / 100f;
        }
        
    }
}
